
import {
    getChromeBookmarkTree,
    openChromeExtensionUrl,
    chromeStoreObjectToStorage,
    chromeRestoreStorageToObject,
    chromeOpenUrl,
    chromeDownload,
    chromeSSOAuthLogin,
    chromeSendMessage, chromeFindBookmarkPath
} from "@/utils/browser/chrome";
import {BrowserType} from "@/utils/constants";
import {getBrowserType} from "@/utils/utils";

/**
 * 目前来看，似乎所有浏览器都可以通用chrome的库，暂时没啥用，后续如果有浏览器不能用，或者需要定制，直接在这加就好了
 */
class BrowserDriver {
    browserType: BrowserType;
    getBookmarkTree: Function | null = null;
    openExtensionUrl: Function | null = null;
    storeObjectToStorage: Function | null = null;
    restoreStorageToObject: Function | ((key: String) => Promise<any>) | null = null;
    openUrl: Function | null = null;
    download: Function | null = null;
    ssoAuthLogin: Function | null = null;
    sendMessage: Function | null = null;
    findBookmarkPath: Function | null = null;

    constructor(browserType: BrowserType = getBrowserType()) {
        this.browserType = browserType;
        switch (true) {
            case this.browserType === BrowserType.edge:
                // todo
                console.info("Edge浏览器驱动支持，未完待续...");
                break;
            case this.browserType === BrowserType.qqbrowser:
                // todo
                console.info("QQ浏览器驱动支持，未完待续...");
                break;
            case this.browserType === BrowserType.firefox:
                // todo
                console.info("Firefox浏览器驱动支持，未完待续...");
                break;
            case this.browserType === BrowserType.chrome:
                this.loadChrome();
                break;
            default:
                this.loadChrome();
                console.info("浏览器驱动不支持，默认使用Chrome，未完待续...");
                break;
        }
    }

    loadChrome() {
        this.getBookmarkTree = getChromeBookmarkTree;
        this.openExtensionUrl = openChromeExtensionUrl;
        this.storeObjectToStorage = chromeStoreObjectToStorage;
        this.restoreStorageToObject = chromeRestoreStorageToObject;
        this.openUrl = chromeOpenUrl;
        this.download = chromeDownload;
        this.ssoAuthLogin = chromeSSOAuthLogin;
        this.sendMessage = chromeSendMessage;
        this.findBookmarkPath = chromeFindBookmarkPath;
    }
}


export {BrowserDriver};